package com.lfy.kcat.content.controller.ai.controller;

import org.springframework.ai.chat.messages.Message;
import org.springframework.ai.chat.messages.UserMessage;
import org.springframework.ai.chat.model.ChatResponse;
import org.springframework.ai.chat.prompt.Prompt;
import org.springframework.ai.chat.prompt.SystemPromptTemplate;
import org.springframework.ai.deepseek.DeepSeekChatModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

import static kotlin.reflect.jvm.internal.impl.builtins.StandardNames.FqNames.list;
import static kotlin.reflect.jvm.internal.impl.builtins.StandardNames.FqNames.map;

@RestController
@RequestMapping("/deepseek")
public class DeepSeekController {

    @Autowired
    private DeepSeekChatModel chatModel;

    @RequestMapping("/chat")
    public ChatResponse chat(@RequestParam ("msg")String message) {
        // 用户消息
        Message userMessage = new UserMessage(message);
        // 创建系统提示模板
        String systemText = "你是一个{name}";
        SystemPromptTemplate systemPromptTemplate =
            new SystemPromptTemplate(systemText);

        Message systemMessage = systemPromptTemplate
            .createMessage(Map.of("name", "猫娘"));
        // 创建系统提示
        //todo: 添加调用模型的代码
        //所有提示词=系统提示+用户输入
        Prompt prompt = new Prompt(List.of(userMessage, systemMessage));

        return chatModel.call(prompt);
    }

}
